<?php
/*
 * Author:  Somnath Shinde- soma.shinde@gmail.com Mobile No:- 9423792564
 * 
 * Create Date: 
 * 
 * Version of MYSQL_to_PHP: 1.1
 * 
 * Ranzani( YZ'S );
 * 
 */
//require_once 'classes/DataBaseMysql.class.php';

Class BaseXrays {

	protected $m_intId;
	protected $m_intPatientId;
	protected $m_strSubject;
	protected $m_strDescription;
	protected $m_strRemark;
	protected $m_intChargeTypeId;
	protected $m_intChargeId;
	protected $m_intChargeAmount;
	protected $m_intDoctorId;
	protected $m_intCasePaperId;
	protected $m_intDocumentAttachmentPath;
	protected $m_intAttachmentId;
	protected $m_strCreatedOn;
	protected $connection;

	public function  __construct() {
		if( true == isset( $_SERVER['connection'] ) ) {
			$this->connection = $_SERVER['connection'];
		}
	}

	
	/*******************************************************************************************
	******************************** get Functions *********************************************
	*******************************************************************************************/

	public function getId(){
		return $this->m_intId;
	}

	public function getPatientId(){
		return $this->m_intPatientId;
	}

	public function getSubject(){
		return $this->m_strSubject;
	}

	public function getDescription(){
		return $this->m_strDescription;
	}

	public function getRemark(){
		return $this->m_strRemark;
	}

	public function getChargeTypeId(){
		return $this->m_intChargeTypeId;
	}

	public function getChargeId(){
		return $this->m_intChargeId;
	}

	public function getChargeAmount(){
		return $this->m_intChargeAmount;
	}

	public function getDoctorId(){
		return $this->m_intDoctorId;
	}

	public function getCasePaperId(){
		return $this->m_intCasePaperId;
	}

	public function getDocumentAttachmentPath(){
		return $this->m_intDocumentAttachmentPath;
	}

	public function getAttachmentId(){
		return $this->m_intAttachmentId;
	}

	public function getCreatedOn(){
		return $this->m_strCreatedOn;
	}
	
	/*******************************************************************************************
	********************************* set Functions ********************************************
	*******************************************************************************************/

	public function setId( $Id ){
		$this->m_intId = $Id;
	}

	public function setPatientId( $PatientId ){
		$this->m_intPatientId = $PatientId;
	}

	public function setSubject( $Subject ){
		$this->m_strSubject = $Subject;
	}

	public function setDescription( $Description ){
		$this->m_strDescription = $Description;
	}

	public function setRemark( $Remark ){
		$this->m_strRemark = $Remark;
	}

	public function setChargeTypeId( $ChargeTypeId ){
		$this->m_intChargeTypeId = $ChargeTypeId;
	}

	public function setChargeId( $ChargeId ){
		$this->m_intChargeId = $ChargeId;
	}

	public function setChargeAmount( $ChargeAmount ){
		$this->m_intChargeAmount = $ChargeAmount;
	}

	public function setDoctorId( $DoctorId ){
		$this->m_intDoctorId = $DoctorId;
	}

	public function setCasePaperId( $CasePaperId ){
		$this->m_intCasePaperId = $CasePaperId;
	}

	public function setDocumentAttachmentPath( $DocumentAttachmentPath ){
		$this->m_intDocumentAttachmentPath = $DocumentAttachmentPath;
	}

	public function setAttachmentId( $AttachmentId ){
		$this->m_intAttachmentId = $AttachmentId;
	}

	public function setCreatedOn( $CreatedOn ){
		$this->m_strCreatedOn = $CreatedOn;
	}
	
	/*******************************************************************************************
	********************************* Insert Functions ********************************************
	*******************************************************************************************/

	public function insert(){
		return $this->connection->RunQuery( "Insert into XRAYS (patient_id, subject, description, remark, charge_type_id, charge_id, charge_amount, doctor_id, case_paper_id, document_attachment_path, attachment_id, created_on) values (" . $this->getPatientId() . ", '" . $this->getSubject() . "', '" . $this->getDescription() . "', '" . $this->getRemark() . "', " . $this->getChargeTypeId() . ", " . $this->getChargeId() . ", " . $this->getChargeAmount() . ", " . $this->getDoctorId() . ", " . $this->getCasePaperId() . ", " . $this->getDocumentAttachmentPath() . ", " . $this->getAttachmentId() . ", now() )");
	}
	
	/*******************************************************************************************
	********************************* Update Functions ********************************************
	*******************************************************************************************/

	public function update(){
		return $this->connection->RunQuery( "UPDATE XRAYS set  subject= '" . $this->getSubject() . "', description= '" . $this->getDescription() . "', remark= '" . $this->getRemark() . "', charge_type_id= " . $this->getChargeTypeId() . ", charge_id= " . $this->getChargeId() . ", charge_amount= " . $this->getChargeAmount() . ", doctor_id= " . $this->getDoctorId() . ", case_paper_id= " . $this->getCasePaperId() . ", document_attachment_path= " . $this->getDocumentAttachmentPath() . ", attachment_id= " . $this->getAttachmentId() . ", created_on = created_on where id =" . $this->getId() );
	}
	
	/*******************************************************************************************
	********************************* Delete Functions ********************************************
	*******************************************************************************************/

	public function Delete($intId ) {
		$this->connection->RunQuery( "DELETE FROM xrays WHERE id = $intId");
	}

	public function fetchNextId() {
		$result = $this->connection->RunQuery( "SELECT AUTO_INCREMENT as id FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = '" . DB_DATABASE . "' AND TABLE_NAME = 'xrays'" );
		if( false == $result ) return NULL;

		while( $row = $result->fetch_array( MYSQLI_ASSOC ) ) {
			$this->id = $row["id"];
		}

		return $this->id;
	}

}